/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package secondround10;

import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.IOException;
import java.io.PrintStream;
import java.io.IOException;

/**
 * @author robit
 */
public class ElegantDiamond{
    /*
      All neccesary to be defined
      including:
      variable, inner class
    */
    // static int A;
    // static void B();
    // static class C

    /*
       One calculation fits all of the cases.
    */
    static void preReckon(){
        return;
    }

    /*
      calculate the answer
    */
    private static void reckon(int line) {
        int k=sc.nextInt();
        char[][] diam=new char[2*k][2*k];
        sc.nextLine();
        //sys.println(k);
        for(int i=1;i<=2*k-1;i++){
            String str=sc.nextLine();
            char[] tmp=str.toCharArray();
            //sys.println(String.format("%d has length %d",str.length(), tmp.length));
            for(int j=0;j<tmp.length;j++)
                diam[i][j+1]=tmp[j];
        }
        int dx[]={-1,1};
        int dy[]={1,1};
        int maxs=0;
SIZE:   for(int s=k;s>0;s--){
POINT:       for(int p=0;p<2;p++){
                int x,y;
                if(p==0){x=2*k-s;y=k-s+1;}
                else {x=s;y=k-s+1;}
                for(int t0=0;t0<s;t0++)
                for(int t1=0;t1<s;t1++)
                {
                    int fx=x+t0*dx[0]+t1*dx[1],
                        fy=y+t0*dy[0]+t1*dy[1];
                    int sx=x+t1*dx[0]+t0*dx[1],
                        sy=y+t1*dy[0]+t0*dy[1];

                    if(diam[fx][fy]!=diam[sx][sy])continue POINT;
                }

                maxs=s;
                break SIZE;
            }
        }

        int Dx[]={-1,-1};
        int Dy[]={-1,1};
        int maxS=0;
SIZE:   for(int S=k;S>0;S--){
POINT:       for(int p=0;p<2;p++){
                int x,y;
                if(p==0){x=k+S-1;y=2*k-S;}
                else {x=k+S-1;y=S;}
                for(int t0=0;t0<S;t0++)
                for(int t1=0;t1<S;t1++)
                {
                    int fx=x+t0*Dx[0]+t1*Dx[1],
                        fy=y+t0*Dy[0]+t1*Dy[1];
                    int sx=x+t1*Dx[0]+t0*Dx[1],
                        sy=y+t1*Dy[0]+t0*Dy[1];

                    if(diam[fx][fy]!=diam[sx][sy])continue POINT;
                }

                maxS=S;
                break SIZE;
            }
        }

        int ans = (3*k-maxs-maxS)*(3*k-maxs-maxS)-k*k;
        out.println(String.format("Case #%d: %d",line,ans));

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        /*
           Pre-computing for all cases
        */

        // Just in case!
        //preReckon();
        //while((char)read()!='P');

        /*
          Input-output
        */
        boolean test=false;
        boolean small=false;
        String prob="A";
        String filename;
        if(test) filename="test";
        else{
            if(small) filename=prob+"-small-practice";
            else filename=prob+"-large-practice";
        }
        try {
            /*
               Init IO,plus determination of input line number
             */
            initFileIO(filename);
            int lineNums=sc.nextInt();
            for (int i = 1; i <= lineNums; i++) {
                reckon(i);
                sys.println("case:"+i);
            }
        } finally {
            endIO();
        }
    }

    private static Scanner sc = null;
    private static PrintWriter out,anl = null;
    private static PrintStream sys=System.out;
    public final static int OUTFILE=0,ANALFILE=1;

    public static void  initFileIO(String filename) throws IOException{
        sc = new Scanner(
                new BufferedReader(new FileReader(filename+".in")));
            //s.useLocale(Locale.US);
        out = new PrintWriter(
                new BufferedWriter(new FileWriter(filename+".out")));
        anl = new PrintWriter(
                new BufferedWriter(new FileWriter(filename+".anal")));

    }

    public static void endIO(){
        sc.close();
        out.close();
    }

}
